package com.umanji.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public final class Util {

	private static final String defaultEncoding;

    static {
        // BEGIN android-changed
        String encoding = System.getProperty("file.encoding");
        // END android-changed
        if (encoding != null) {
        	try {
        		"".getBytes(encoding);
            } catch (Throwable t) {
                encoding = null;
            }
        }
        defaultEncoding = encoding;
    }

    public static String getCrossDomainPageForAjax(String fullURL) {
    	StringBuilder sb = new StringBuilder();
    	try {
			
    		URL page = new URL(fullURL); // Process the URL far enough to find the right handler
	    	URLConnection urlc = page.openConnection();
		    urlc.setUseCaches(false); // Don't look at possibly cached data
		    System.out.println("Content-type = " + urlc.getContentType()); // See what's here
		    System.out.println("Content-length = " + urlc.getContentLength()); // See how much of it there is
		    String line;
		    // Read it all and print it out
    		BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
    		while  ((line = br.readLine()) != null) {
    			sb.append(line).append("\n");
    		}
		}
		catch (MalformedURLException mue) {
			System.out.println(fullURL + " is not a URL that can be resolved");
			return fullURL + " is not a URL that can be resolved";
		}
		catch (IOException ie) {
			ie.printStackTrace();
			return "io exception";
		}
	    return sb.toString();
    }

}
